package com.ruoyi.yyq.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.yyq.domain.CarWithdrawal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.yyq.domain.CarMerchantBalance;
import com.ruoyi.yyq.service.ICarMerchantBalanceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商家余额Controller
 * 
 * @author 尹永青
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/balance")
@CrossOrigin
public class CarMerchantBalanceController extends BaseController
{
    @Autowired
    private ICarMerchantBalanceService carMerchantBalanceService;

    /**
     * 查询商家余额列表
     */
    @RequiresPermissions("yyq:balance:list")
    @GetMapping("/list")
    public TableDataInfo list(CarMerchantBalance carMerchantBalance)
    {
        startPage();
        List<CarMerchantBalance> list = carMerchantBalanceService.selectCarMerchantBalanceList(carMerchantBalance);
        return getDataTable(list);
    }

    @RequiresPermissions("yyq:record:list")
    @GetMapping("/listByMid/{mid}")
    public AjaxResult listByMid(@PathVariable("mid") Long mid){
        CarMerchantBalance carMerchantBalance = new CarMerchantBalance();
        carMerchantBalance.setMid(mid);
        List<CarMerchantBalance> list = carMerchantBalanceService.selectCarMerchantBalanceList(carMerchantBalance);
        return success(list);
    }
    /**
     * 导出商家余额列表
     */
    @RequiresPermissions("yyq:balance:export")
    @Log(title = "商家余额", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarMerchantBalance carMerchantBalance)
    {
        List<CarMerchantBalance> list = carMerchantBalanceService.selectCarMerchantBalanceList(carMerchantBalance);
        ExcelUtil<CarMerchantBalance> util = new ExcelUtil<CarMerchantBalance>(CarMerchantBalance.class);
        util.exportExcel(response, list, "商家余额数据");
    }

    /**
     * 获取商家余额详细信息
     */
    @RequiresPermissions("yyq:balance:query")
    @GetMapping(value = "/{balanceId}")
    public AjaxResult getInfo(@PathVariable("balanceId") Long balanceId)
    {
        return success(carMerchantBalanceService.selectCarMerchantBalanceByBalanceId(balanceId));
    }

    /**
     * 新增商家余额
     */
    @RequiresPermissions("yyq:balance:add")
    @Log(title = "商家余额", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarMerchantBalance carMerchantBalance)
    {
        return toAjax(carMerchantBalanceService.insertCarMerchantBalance(carMerchantBalance));
    }

    /**
     * 修改商家余额
     */
    @RequiresPermissions("yyq:balance:edit")
    @Log(title = "商家余额", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarMerchantBalance carMerchantBalance)
    {
        return toAjax(carMerchantBalanceService.updateCarMerchantBalance(carMerchantBalance));
    }

    /**
     * 删除商家余额
     */
    @RequiresPermissions("yyq:balance:remove")
    @Log(title = "商家余额", businessType = BusinessType.DELETE)
	@DeleteMapping("/{balanceIds}")
    public AjaxResult remove(@PathVariable Long[] balanceIds)
    {
        return toAjax(carMerchantBalanceService.deleteCarMerchantBalanceByBalanceIds(balanceIds));
    }
}
